package com.stormragetech.teamwork.module.project.spring.dao.impl;

import com.stormragetech.common.exception.StormragetechException;
import com.stormragetech.teamwork.module.project.constant.ProjConstants;
import com.stormragetech.teamwork.module.project.entity.ProjectStruc;
import com.stormragetech.teamwork.module.project.spring.dao.ProjectStrucMongo;
import com.stormragetech.teamwork.spring.dao.MongoDao;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

/**
 * description: //TODO
 *
 * @author: Xue Bin
 * @version: 1.0.0-SNAPSHOT
 */
@Repository
public class ProjectStrucMongoImpl extends MongoDao<ProjectStruc> implements ProjectStrucMongo {

    public ProjectStrucMongoImpl(MongoTemplate template) {
        super(template);
    }

    @Override
    public void create(final ProjectStruc model) throws StormragetechException {

        insert(model, ProjConstants.PROJ_MODEL_COL);

    }

    @Override
    public ProjectStruc findLastStruc() throws StormragetechException {

        Query query = new Query();
        Sort sort = new Sort(Sort.Direction.DESC, "createDate");
        query.with(sort);

        return findOne(query, ProjConstants.PROJ_MODEL_COL, ProjectStruc.class);

    }
}
